home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Tools&Utilities / RagTime External Functions Kit / FirstSample / FirstSample.cpp < prev    next >
C/C++ Source or Header  |  1997-04-24  |  3KB  |  106 lines

  1. #include "FirstSample.h"
  2. #include "RTXFunctsIntf.h"
  3. #include "RTXBackCalls.h"
  4. #include <Memory.h>
  5. #include <OSUtils.h>
  6. #include <Resources.h>
  7. #include <ToolUtils.h>
  8.  
  9. //-------------------------------------------------------------------------------
  10. //        constant for string list defined in 'BXRl' resource, plus constants
  11. //        for the individual strings in the string list.
  12. //-------------------------------------------------------------------------------
  13. enum {
  14.     kValNilStr            = 1,
  15.     kValNumStr,
  16.     kValBoolStr,
  17.     kValDateStr,
  18.     kValTextStr,
  19.     kValIntNumStr,
  20.     kUnknownValStr
  21. };
  22.     
  23. //-------------------------------------------------------------------------------
  24. //        Prototypes
  25. //-------------------------------------------------------------------------------
  26.  
  27. void FillInResultText (short theStrList, short theStrIndex,
  28.                               RTValuePtr theValPtr);
  29.  
  30. //-------------------------------------------------------------------------------
  31. //        main
  32. //-------------------------------------------------------------------------------
  33.  
  34. pascal short main (RTXPtr callBlock) {
  35.     
  36.     short selector = callBlock->selector;
  37.     
  38.     switch (selector) {
  39.         case kInitSelector:
  40.         case kQuitSelector: {
  41.             // nothing to do here
  42.             break;
  43.         }
  44.         case kOpenDocSelector:
  45.         case kCloseDocSelector:
  46.         case kActivateSelector:
  47.         case kDeactivateSelector: {
  48.             // these messages are only sent if 'kWantsMessagesFlag' is set
  49.             // in the 'BXDe' resource.
  50.             break;
  51.         }
  52.         case kTimeSelector: {
  53.             // this messages is only sent if 'needsTime' is set
  54.             // in the 'BXDe' resource.
  55.             break;
  56.         }
  57.         case kExampleAdd: {
  58.             // This function can accept either one or two parameters. If only one is
  59.              // received, then the result is 1 plus the parameter, otherwise the two
  60.              // parameters are added together.
  61.             callBlock->resultDest->valKind = valIntNum;
  62.             long firstLongInt = callBlock->parameter->eIntNum;
  63.             ::GetNextParam (callBlock->backPtr);
  64.             if (callBlock->parameter == NULL) {
  65.                 callBlock->resultDest->eIntNum = 1 + firstLongInt;
  66.             } else {
  67.                 callBlock->resultDest->eIntNum = firstLongInt +             
  68.                                                             callBlock->parameter->eIntNum;
  69.             }
  70.             break;
  71.         }
  72.         case kIdentifyType: {
  73.             // This function returns text identifying the type of of the parameter.
  74.             callBlock->resultDest->valKind = valText;
  75.             short paramKind = callBlock->parameter->valKind;
  76.             short stringNo = kUnknownValStr;    // in case of unknown value type
  77.             if (paramKind == valNil) stringNo = kValNilStr;
  78.             else if (paramKind == valNum) stringNo = kValNumStr;
  79.             else if (paramKind == valBool) stringNo = kValBoolStr;
  80.             else if (paramKind == valDate) stringNo = kValDateStr;
  81.             else if (paramKind == valText) stringNo = kValTextStr;
  82.             else if (paramKind == valIntNum) stringNo = kValIntNumStr;
  83.             FillInResultText (kResourceBase + 1, stringNo, callBlock->resultDest);
  84.             break;
  85.         }
  86.     }
  87.     return noErr;
  88. };
  89.  
  90. //-------------------------------------------------------------------------------
  91. // Fill in the RTValueRec pointed to by theValPtr with the text
  92. // specified by the string list and index.
  93. //-------------------------------------------------------------------------------
  94. void FillInResultText (short theStrList, short theStrIndex,
  95.                               RTValuePtr theValPtr) {
  96.     Str255 theString;                              
  97.  
  98.     ::GetIndString (theString, theStrList, theStrIndex);
  99.     short length = (short) theString[0];
  100.     theValPtr->t.eTextLen = length;
  101.     theValPtr->t.eTextHdl = ::NewHandle (length);
  102.     ::BlockMove (&(theString[1]), *(theValPtr->t.eTextHdl), length);
  103. };
  104.  
  105.  
  106.